import java.util.*;

/*
public class ListNode {
    int val;
    ListNode next = null;

    ListNode() {
        this.val = val;
    }
}*/
public class PalindromeList {
    public boolean chkPalindrome(ListNode A) {
        if (A == null) {
            return true;
        }
        ListNode SBList = new ListNode(0);
        SBList.next = A;
        ListNode fast = SBList;
        ListNode slow = SBList;
        //找中间（前）位置
        while (fast != null && fast.next != null) {
            fast = fast.next.next;
            slow = slow.next;
        }

        //逆置
        ListNode cur = slow.next;

        ListNode next = cur.next;
        ListNode prev = slow;

        while (cur != null) {
            next = cur.next;
            cur.next = prev;
            prev = cur;
            cur = next;
        }

        // 判断
        ListNode curr = prev;
        while (slow != A) {
            if (curr.val != A.val) {
                return false;
            } else {
                curr = curr.next;
                A = A.next;
            }
        }
        return true;
    }
}